<{*资金分配*}>
<div class="row">
	<div id="breadcrumb" class="col-md-12">
		<ol class="breadcrumb">
			<li><a href="index.html">Dashboard</a></li>
			<li><a href="#">Forms</a></li>
			<li><a href="#">Forms elements</a></li>
		</ol>
	</div>
</div>
<div class="well">




	<p class="lead">资金分配</p>
<form id="form">
	<input type="hidden" name="do" value="1" />
	<table class="table">
		<tbody>
		<tr>
			<td>平台渠道</td>
			<td><div >
				<div class="radio-inline"></div>
				<{foreach from=$channel item=item key=key }>
				<div class="radio-inline col-sm-2">
					<label>
						<input type="radio" name="channel" checked value="<{$key}>"> <{$item}>
						<i class="fa fa-circle-o"></i>
					</label>
				</div>
				<{/foreach}>

			</div></td>
			<td></td>
		</tr>
		<tr>
			<td>支付宝金额</td>
			<td><input type="number" id="alipay" name="alipay" class="form-control" placeholder=""  />
			<div id="aliMem"></div>
			</td>
			<td></td>

		</tr>
		<tr>
			<td>支付金额比例</td>
			<td>
				<table class="table" id="ali">
				<tbody>
				<tr>
					<td >10元</td>
					<td><span class="col-sm-3"><input id="ali10" name="ali10"  type="number" class="form-control" placeholder="0%" /></span><span></span></td>
				</tr>
				<tr>
					<td>30元</td>
					<td><span class="col-sm-3"><input id="ali30" name="ali30"  type="number" class="form-control" placeholder="0%" /></span><span></span></td>
				</tr>
				<tr>
					<td>50元</td>
					<td><span class="col-sm-3"><input id="ali50" name="ali50"  type="number" class="form-control" placeholder="0%" /></span><span></span></td>
				</tr>
				<tr>
					<td>100元</td>
					<td><span class="col-sm-3"><input id="ali100" name="ali100" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

				</tr>
				<tr>
					<td>300元</td>
					<td><span class="col-sm-3"><input id="ali300" name="ali300" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

				</tr>
				<tr>
					<td>500元</td>
					<td><span class="col-sm-3"><input id="ali500" name="ali500" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

				</tr>
				<tr>
					<td>1000元</td>
					<td><span class="col-sm-3"><input id="ali1000" name="ali1000" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

				</tr>
				<tr>
					<td>3000元</td>
					<td><span class="col-sm-3"><input id="ali3000" name="ali3000" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

				</tr>
				</tbody>
			</table>

			</td>
			<td></td>

		</tr>
		<tr>
			<td>微信支付金额</td>
			<td><input type="number" id="wxpay" name="wxpay" class="form-control" placeholder="" />
				<div id="wxMem"></div>
			</td>
			<td></td>

		</tr>
		<tr>
			<td>支付金额比例</td>
			<td>
				<table class="table" id="wx">
					<tbody>
					<tr>
						<td>10元</td>
						<td><span class="col-sm-3"><input id="wx10" name="wx10"  type="number" class="form-control" placeholder="0%" /></span><span></span></td>
					</tr>
					<tr>
						<td>30元</td>
						<td><span class="col-sm-3"><input id="wx30" name="wx30"  type="number" class="form-control" placeholder="0%" /></span><span></span></td>
					</tr>
					<tr>
						<td>50元</td>
						<td><span class="col-sm-3"><input id="wx50" name="wx50"  type="number" class="form-control" placeholder="0%" /></span><span></span></td>
					</tr>
					<tr>
						<td>100元</td>
						<td><span class="col-sm-3"><input id="wx100" name="wx100"  type="number" class="form-control" placeholder="0%" /></span><span></span></td>
					</tr>
					<tr>
						<td>300元</td>
						<td><span class="col-sm-3"><input id="wx300" name="wx300" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

					</tr>
					<tr>
						<td>500元</td>
						<td><span class="col-sm-3"><input id="wx500" name="wx500" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

					</tr>
					<tr>
						<td>1000元</td>
						<td><span class="col-sm-3"><input id="wx1000" name="wx1000" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

					</tr>
					<tr>
						<td>3000元</td>
						<td><span class="col-sm-3"><input id="wx3000" name="wx3000" type="number" class="form-control" placeholder="0%" /></span><span></span></td>

					</tr>

					</tbody>
				</table>

			</td>
			<td></td>

		</tr>
		<tr>
			<td></td>
			<td><button type="button" id="moneyAssignBtn" class="btn btn-primary btn-lg"> 分 配 </button></td>
			<td></td>
		</tr>
		</tbody>
	</table>
</form>
</div>
<script>
	$("#moneyAssignBtn").on('click',
			function(){
				var cfg=0;
				if($("#alipay").val()){
					var totalScale=($('#ali10').val()*1)
							+($('#ali30').val()*1)
							+($('#ali50').val()*1)
							+($('#ali100').val()*1)
							+($('#ali300').val()*1)
							+($('#ali500').val()*1)
							+($('#ali1000').val()*1)
							+($('#ali3000').val()*1);
					if(totalScale!=100){
						alert("支付宝支付分配比例未达到100%");
						return;
					}
					cfg=1;
				}
				if($("#wxpay").val()){
					var totalScale=($('#wx10').val()*1)
							+($('#wx30').val()*1)
							+($('#wx50').val()*1)
							+($('#wx100').val()*1)
							+($('#wx300').val()*1)
							+($('#wx500').val()*1)
							+($('#wx1000').val()*1)
							+($('#wx3000').val()*1);
					if(totalScale!=100){
						alert("微信支付分配比例未达到100%");
						return;
					}
					cfg=1
				}
				if(cfg==0){
					alert("未配置分配金额")
					return;
				}
				$.post('<{u(moneyAssign)}>',$('#form').serialize(),function(ret){

					if(ret.status==0){
						alert("分配成功");
					}else{
						alert(ret.msg);
					}


				},'json')


			}
	);

	$(document).ready(function(){
		$('#ali .col-sm-3>input').on('keyup',function(){
			var total=$('#alipay').val();
			var $this=$(this);
			var tmpMoney=Math.floor(total*$this.val()/100);
			var price=parseInt($this.attr('id').substr(3));
			var tmpNum=Math.floor(tmpMoney/price);
			if(tmpMoney>0 && tmpNum*price!=tmpMoney){//warning
				$this.parent().next().css({'color':'red'}).html('预估金额：'+tmpMoney+',预估笔数：'+tmpNum);
			}else{
				$this.parent().next().css({'color':'black'}).html('预估金额：'+tmpMoney+',预估笔数：'+tmpNum);
			}
			var sum=0;
			$('#ali .col-sm-3>input').each(function(){sum+=this.value*1;})

			$('#aliMem').text("已分配比例："+sum+"%,剩余："+(100-sum)+'%');
		});

		$('#wx .col-sm-3>input').on('keyup',function(){
			var total=$('#wxpay').val();
			var $this=$(this);
			var tmpMoney=Math.floor(total*$this.val()/100);
			var price=parseInt($this.attr('id').substr(2));
			var tmpNum=Math.floor(tmpMoney/price);
			if(tmpMoney>0 && tmpNum*price!=tmpMoney){//warning
				$this.parent().next().css({'color':'red'}).html('预估金额：'+tmpMoney+',预估笔数：'+tmpNum);
			}else{
				$this.parent().next().css({'color':'black'}).html('预估金额：'+tmpMoney+',预估笔数：'+tmpNum);
			}
			var sum=0;
			$('#wx .col-sm-3>input').each(function(){sum+=this.value*1;})

			$('#wxMem').text("已分配比例："+sum+"%,剩余："+(100-sum)+'%');
		});
	})

</script>


